import { MsgInfo, useMessage } from "@/hooks/useMessage";
import { notifyType } from "@/utils/constants";
import { ElTag } from "element-plus";

export default defineComponent({
	props: {
		content: String
	},
	emits: [],
	setup(props) {
		const state = reactive({
			msgInfo: {} as MsgInfo,
			tag: {
				type: "" as "" | "success" | "warning" | "info" | "danger",
				name: ""
			}
		});
		state.msgInfo = useMessage().getMsgContent(props.content || "");
		switch (state.msgInfo.type) {
			case notifyType.email:
				state.tag.type = "success";
				state.tag.name = "邮件";
				break;
			case notifyType.sms:
				state.tag.type = "";
				state.tag.name = "短信";
				break;
			case notifyType.message:
				state.tag.type = "success";
				state.tag.name = "消息";
				break;
			default:
				state.tag.type = "danger";
				state.tag.name = "其他";
				break;
		}
		return () => {
			return (
				<ElTag type={state.tag.type} class="mr-2" effect="dark">
					{state.tag.name}
				</ElTag>
			);
		};
	}
});
